﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using WebTemplate.DAL.Entities;
using WebTemplate.DAL.Repositories;
using System.Net.Mail;

namespace WebTemplate.Web.Membership
{
    public partial class SendEmailReset : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            MemberReprositry reprositry = new MemberReprositry();
            MembersSearchCriteria search = new MembersSearchCriteria();
            Members member = new Members();
            search.UserID = UsersID.Text;
            member = reprositry.Select(search).First();
            if (member != null)
            {
                SendMail(member);
            }



        }

        public void SendMail(Members sender)
        {
            MailMessage message = new MailMessage();
            message.To.Add(new MailAddress(sender.Email));
            message.Subject = "Welcome to webtemplate";
            this.ResolveUrl("~/Membership/ResetPassword.aspx ");
            Guid IsReset = Guid.NewGuid();
            message.Body = " To change your password follow this link http://localhost:25968/Membership/ResetPassword.aspx?IsReset" + IsReset + "Reset Password" ;
            SmtpClient client = new SmtpClient();
            client.Send(message);
        }
    }
}